//
//  LLPImageData.m
//  LLP
//
//  Created by psy on 12-10-12.
//  Copyright (c) 2012年 Porcellio. All rights reserved.
//

#import "LLPImageData.h"
#import "LLPImageFileCache.h"

@implementation LLPImageData

#pragma mark - basic methods
- (void)dealloc{
    [_imgNamesArray release];
    [_uiimagesArray release];
    [_imgName release];
    [super dealloc];
}
- (id)initWithDic:(NSDictionary*)tmpDic{
    self = [super init];
    if (self) {
        self.imgNamesArray = [tmpDic valueForKey:@"imgFilesArray"];
        self.filterType = [[tmpDic valueForKey:@"filterType"]intValue];
        self.imgName = [tmpDic valueForKey:@"imgName"];
        
        _uiimagesArray = [[NSMutableArray alloc]init];
        for (NSString* fileName in self.imgNamesArray) {
            UIImage* tmpImg = [[LLPImageFileCache sharedImageFileCache]imgFileDataByName:fileName];
            if (tmpImg) {
              [_uiimagesArray addObject:tmpImg];  
            }
            
        }
    }
    return self;
}

- (id)initWithImgNamesArray:(NSArray*)tmpImgNamesArray
           andUIImagesArray:(NSArray*)tmpUIImagesArray
              andFilterType:(LLPFilterType)tmpType
                andFileName:(NSString*)tmpImgName{
    self = [super init];
    if (self) {
        self.imgNamesArray = [NSMutableArray arrayWithArray:tmpImgNamesArray];
        self.uiimagesArray = [NSMutableArray arrayWithArray:tmpUIImagesArray];
        self.filterType = tmpType;
        self.imgName = tmpImgName;
    }
    return self;
}

- (void)saveImgArray{
    //这里存储所有的image，如果已经存了，就直接跳过
}

#pragma mark -

- (void)removeImageByIndex:(int)tmpIndex{
    if (tmpIndex < self.imgNamesArray.count) {
        return;
    }
    [self.imgNamesArray removeObjectAtIndex:tmpIndex];
    [self.uiimagesArray removeObjectAtIndex:tmpIndex];
}
- (void)insetImage:(NSString*)tmpImgName
       withUIImage:(UIImage*)tmpUIImage
           inIndex:(int)tmpIndex{
    if (tmpIndex >= self.imgNamesArray.count) {
        return;
    }
    [self.imgNamesArray insertObject:tmpImgName atIndex:tmpIndex];
    [self.uiimagesArray insertObject:tmpUIImage atIndex:tmpIndex];
}
- (void)setFilterType:(LLPFilterType)tmpType{
    self.filterType = tmpType;
}

- (NSDictionary*)convertToDic{
    NSMutableDictionary* tmpDic = [NSMutableDictionary dictionary];
    [tmpDic setValue:self.imgNamesArray forKey:@"imgFilesArray"];
    [tmpDic setValue:self.imgName forKey:@"imgName"];
    [tmpDic setValue:[NSNumber numberWithInt:self.filterType] forKey:@"filterType"];
    return tmpDic;
}

@end
